package com.yang;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class ShowActivity extends AppCompatActivity {

    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        listView = findViewById(R.id.listView);
        ContactHelper contactHelper = new ContactHelper(ShowActivity.this);
        ArrayList<Map<String, Object>> list = contactHelper.queryListMap();
        SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.show_layout, new String[]{"name", "tel"},
                new int[]{R.id.name, R.id.tel});
        listView.setAdapter(adapter);
//        listView.setOnClickListener(view -> {
//            listView.getAdapter();
//        });
        listView.setOnItemClickListener((adapterView, view, i, l) -> {
            Map<String,Object> map = (Map<String, Object>) adapterView.getItemAtPosition(i);
            Intent intent = new Intent();
            intent.setAction("android.intent.action.DIAL");
            intent.setData(Uri.parse("tel:" + map.get("tel")));
            startActivity(intent);
//                Toast.makeText(getApplicationContext(), "电话："+ map.get("tel"), Toast.LENGTH_SHORT).show();
        });
    }
}